/**
 * 
 */
package net.homelinux.ajay.net.ondisk.view.client;


import net.homelinux.ajay.net.ondisk.model.client.AppObject;
import net.homelinux.ajay.net.ondisk.model.client.Collection;
import net.homelinux.ajay.net.ondisk.model.client.Collections;
import net.homelinux.ajay.net.ondisk.view.menu.client.CollectionsMenuBuilder;

import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.Tree;
import com.google.gwt.user.client.ui.Widget;

/**
 * @author ajay
 *
 */
public class CollectionsTreeItem extends AppTreeItem {
  private final static String imageUrl = "images/tsclient.png";
  
  private static Image getImage() {
    Image img = new Image(imageUrl);
    img.setSize("24", "24");
    return img;
  }

  private Collections collections;

  /**
   * 
   */
  public CollectionsTreeItem() {
  }

  /**
   * @param html
   */
  public CollectionsTreeItem(String html) {
    super(html, getImage());
    collections =  new Collections();
  }

//  /**
//   * @param widget
//   */
//  public CollectionsTreeItem(Widget widget) {
//    super(widget);
//  }
  
  
  public static CollectionsTreeItem makeChild(String content, Tree parent) {
    CollectionsTreeItem itm2;
    itm2 = new CollectionsTreeItem(content);
//    String itemwidth = "10em";
//    itm2.setWidth(itemwidth);
    if(parent!=null){
      parent.addItem(itm2);
    }
    return itm2;
    
  }

  public CollectionTreeItem makeCollection(String string) {
    return CollectionTreeItem.makeCollectionTreeItem(string,this);
  }
//
//  public void onDeselect() {
//    // NOOP
//    
//  }
//
//  public void onSelect() {
//    // NOOP
//    
//  }

  public void onMetaChange(AppObject meta) {
    // TODO implement onMetaChange
    
  }

  protected CommandsMenu getCommandsMenu() {
    return CollectionsMenuBuilder.getInstance().makeContextMenu();
  }

  public Collections getMeta() {
    return collections;
  }

  public boolean addCollection(String name) {
    if(getMeta().getCollection(name)!=null){
      return false;
    }
    //Collection c = getMeta().makeCollection(name);
    makeCollection(name);
    return true;
  }


}
